package com.java123.t2;

public class ShopCart {

	/**
	 * 总价
	 */
	public static double totalCount = 0.0;

	/**
	 * 超市篮子，推车
	 */
	public String[] shops;

	/**
	 * 当前商品数量
	 */
	public static int num = 0;

	public ShopCart(int size) {
		this.shops = new String[size];
	}

	/**
	 * 添加商品
	 * @param shopName
	 * @param price
	 */
	public void add(String shopName, double price) {
		int index = num;
		shops[index] = shopName;
		totalCount += price;
		num++;
	}

	/**
	 * 查看购物车，返回购物车信息
	 * 
	 * @return
	 */
	public String calShopCart() {
		String result = "购买的商品有：\n";
		// 遍历购物车
		for (int i = 0; i < num; i++) {
			result = result + shops[i] + "\n";
		}
		result = result + "总价：" + totalCount;
		return result;
	}
}
